<template>
  <a-select :value="value1" placeholder="请选择" @change="handleChange">
    <a-select-option value="">请选择</a-select-option>
    <a-select-option :value="item.value" :key="item.value" v-for="item in list">{{ item.title }}</a-select-option>
  </a-select>
</template>
<script>
  import {queryDictModelByCode} from '@/api/gis'

  export default {
    model: {
        props: 'value',
        event: 'change',
    },
    props: {
        value: {
            type: [String, Number],
            default: '',
        },
        dictName: {
            type: String,
            default: '',
        }
    },
    watch: {
        value(newData){
            this.value1 = newData;
        }
    },
    data(){
        return {
            value1: '', //值
            list: [], //字典列表数据
        }
    },
    methods: {
        queryDictModelByCodes(){
            const params = {
                dictName: this.dictName,
            }
            queryDictModelByCode(params).then(res => {
                if(res.success){
                    this.list = res.result || [];
                }
            })
        },
        handleChange(val){
            this.value1 = val;
            this.$emit('change',val);
        }
    },
    mounted(){
        //初始化数据
        this.queryDictModelByCodes();
    }
}
</script>